/*
 * Assignable.java
 * 
 * last update: 15.01.2010 by Stefan Saru
 * 
 * author:	Alec(panovici@elcom.pub.ro)
 *
 * Obs:  
 */
package engine;

import java.util.*;
import java.io.Serializable;

/**
 * Specifies the basics for continuous assignement.
 */
@SuppressWarnings("serial")
abstract class Assignable implements Serializable{

	Vector data;  //stores all the assignements made to this DataHolder
	//contains ContBitSelects see BitVector.compute()  
	protected static final int X = BitVector.X, Z=BitVector.Z;


	//the value arbitration tables for multiple assignement
	//and equal strength

	public static final int lookupTableWire[][]={
		//      |   0  1  X  Z 
		//------+----------
		/*    0 */{ 0, X, X, 0},

		/*    1 */{ X, 1, X, 1},

		/*    X */{ X, X, X, X},

		/*    Z */{ 0, 1, X, Z}
	};

	public static final int lookupTableWand[][]={
		//      |   0  1  X  Z 
		//------+----------
		/*    0 */{ 0, 0, 0, 0},

		/*    1 */{ 0, 1, X, 1},

		/*    X */{ 0, X, X, X},

		/*    Z */{ 0, 1, X, X}
	};

	public static final int lookupTableWor[][]={
		//      |   0  1  X  Z 
		//------+----------
		/*    0 */{ 0, 1, X, 0},

		/*    1 */{ 1, 1, 1, 1},

		/*    X */{ X, 1, X, X},

		/*    Z */{ 0, 1, X, Z}
	};

	public static final int lookupTableTri0[][]={
		//      |   0  1  X  Z 
		//------+----------
		/*    0 */{ 0, X, X, 0},

		/*    1 */{ X, 1, X, 1},

		/*    X */{ X, X, X, X},

		/*    Z */{ 0, 1, X, 0}
	};

	public static final int lookupTableTri1[][]={
		//      |   0  1  X  Z 
		//------+----------
		/*    0 */{ 0, X, X, 0},

		/*    1 */{ X, 1, X, 1},

		/*    X */{ X, X, X, X},

		/*    Z */{ 0, 1, X, 1}
	};

	// hope these two are right...
	public static final int lookupTableSupply0[][] = lookupTableWire;
	public static final int lookupTableSupply1[][] = lookupTableWire;


	public static int lookupTables[][][] = {lookupTableWire,
		lookupTableWand,
		lookupTableWor,
		lookupTableTri0,
		lookupTableTri1,
		lookupTableSupply0,
		lookupTableSupply1,
		lookupTableWire /*here I
                                                          assume that a driven trireg
                                                          acts like a simple
                                                          wire. I
                                                          really don't know 
                                                          whether it
                                                          is right, 
                                                          but the std. doesn't say 
                                                          a word about
                                                          the question
		 */
	}; 

	//these can be used as indexes in lookupTables, so the type-to-table mappin' is done easier

	public static final int typeWire  = 0;
	public static final int typeWand  = 1;
	public static final int typeWor   = 2;
	public static final int typeTri0  = 3;
	public static final int typeTri1  = 4;
	public static final int typeSupply0 = 5;
	public static final int typeSupply1 = 6;

	public static final int typeTrireg  = 7;
	public static final int typeTriand  = 8;
	public static final int typeTrior   = 9;

	//                                            0  1  2  3  4  5  6  7
	public static final int  initValDefaults[] = {Z, Z, Z, 0, 1, 0, 1, X};


	Assignable(){
		data = new Vector();
	}

	void addAssignement(ContBitSelect wc) {
		data.addElement(wc);
	}

	void removeAssignement(ContBitSelect wc) {
		data.removeElement(wc);
	}

	/**
	 * this should compute the actual value of the data, 
	 *  by considering all the assigned values
	 * @return e vactor whose first element is the BitVector with the
	 * computed values and the (optionally) second is the vector with the
	 * computed strengths
	 */
	abstract Object[] compute()throws InterpretTimeException;

}




